import jwt
import datetime
# jwt encode token编码
from django.conf import settings
class JWTTool:
    def getToken(self,userid,account):
        data = {
            "userid":userid,
            "account":account,
            "exp":datetime.datetime.now() + datetime.timedelta(hours = 1)
        }
        return "Bearer " + jwt.encode(payload=data,key=settings.SECRET_KEY)
    def checkToken(self,token):
        return jwt.decode(token,key=settings.SECRET_KEY,algorithms="HS256")
tooljwt = JWTTool()
# print(tool.getToken(1,"admin"))
# print(tool.checkToken('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyaWQiOjEsImFjY291bnQiOiJhZG1pbiIsImV4cCI6MTczNDk1NTgzM30.68pP0BHYbvH25KfRcPEsZzkx7UF934TMV6utooMWOwo'))
#
















